package com.dd.controller;

import com.dd.entity.User;
import com.dd.util.DateUtil;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

//@Controller + @ResponseBody = @RestController
@RestController
@RequestMapping("/user")
public class UserController {

    //新增用户
    @PostMapping("/saveUser")
    public String saveUser(@RequestBody User user){
        System.out.println("接收新增用户信息=====>"+user);

        return "新增用户";
    }

    //修改用户信息
    @PostMapping("/updateUser")
    public String updateUser(@RequestBody User user){
        System.out.println("接收修改用户信息=====>"+user);

        return "修改用户信息";
    }


    //删除用户用户信息
    @GetMapping("/deleteUser")
    public String deleteUser(Integer userId){
        System.out.println("接收删除用户信息=====>"+userId);

        return "删除用户信息";
    }


    //获取用户列表
    @GetMapping("/getUserList")
    public List<User> getUserList(String userName,String tel){

        List<User> users = new ArrayList<>();

        User user = new User();
        user.setUserId(1);
        user.setUserName("张三");
        user.setPassword("123456");
        user.setSex("男");
        user.setTel("123456789");
        user.setRegisterDate(DateUtil.stringToDate("2024-10-27", "yyyy-MM-dd"));
        user.setImageUrl("");
        users.add(user);

        User user1 = new User();
        user1.setUserId(1);
        user1.setUserName("李四");
        user1.setPassword("123");
        user1.setSex("男");
        user1.setTel("15478985236");
        user1.setRegisterDate(DateUtil.stringToDate("2024-01-27", "yyyy-MM-dd"));
        user1.setImageUrl("");
        users.add(user1);

        return users;

    }


    //获取指定用户信息
    @GetMapping("/getUserById")
    public User getUserById(Integer userId){

        User user = new User();
        user.setUserId(1);
        user.setUserName("张三");
        user.setPassword("123456");
        user.setSex("男");
        user.setTel("123456789");
        user.setRegisterDate(DateUtil.stringToDate("2024-10-27", "yyyy-MM-dd"));
        user.setImageUrl("");

        return user;
    }
}
